<template>
  <Header></Header>
  <Drawer></Drawer>
  <el-breadcrumb separator="/" style="font-size: 20px;color: #FF5C82;">
    <el-breadcrumb-item :to="{ path: '/Home' }">首页</el-breadcrumb-item>
    <el-breadcrumb-item :to="{ path: '/Home' }">{{ labName }}</el-breadcrumb-item>
    <el-breadcrumb-item :to="{ path: '/GravidaList/'+ groupId }">档案管理</el-breadcrumb-item>
    <el-breadcrumb-item>开始测评</el-breadcrumb-item>
  </el-breadcrumb>

  <div class = 'pageListBotton'>
    <el-button :icon="Expand" style="color: white;background: #2196f3" round @click="pageList">
      档案列表
    </el-button>
    <span class="onBtnRight"  @click="onHome"><img src="../assets/img/pageList_qiehuan.png" alt=""> 更换群体</span>
  </div>

  <AdultLeft></AdultLeft>

  <el-card class="right-box-card"  v-if="onBmishow === 1">
      <div class="right-btn">
        <el-button type="primary" class="BMIprimary"   @click="bmifx" >
          BMI分析
        </el-button>
        <p><img src="../assets/img/evaluaction_mark.png" alt="" style="width: 16px;height: 16px;padding-right: 10px">BMI、膳食营养等科学数据分析</p>
      </div>
      <div class="right-btn">
        <el-button type="primary" class="BMIprimary"  @click="drawer = true">
          体成分测评
        </el-button>
        <p><img src="../assets/img/evaluaction_mark.png" alt="" style="width: 16px;height: 16px;padding-right: 10px">请测评者手持仪器，点击按钮开始体成分分析</p>
      </div>
  </el-card>

  <el-card class="right-box-card" v-else-if="onBmishow === 2">
  <div class="fenxing">
    <div class="fxi">
      <img src="../assets/img/ri_baby-scan-fil.svg" alt style="width: 120px;height: 120px;" /> 分析中...
    </div>
    <div class="wing">
      正在进行BMI分析...
      <span :style="{'color':'#E27350'}">{{percentage}}</span> %
    </div>
    <el-progress
        :percentage="percentage"
        :style="{'width':'70%','margin':'100px auto','padding-left':'50px'}"
    ></el-progress>
  </div>
  </el-card>

  <el-card class="right-box-card" v-else-if="onBmishow === 3">
    <div class="fenxing">
      <div class="fxi">
        <img src="../assets/img/evaluation_bmi_true.png" alt style="width: 120px;height: 120px;" /> BMI分析完成
      </div>
      <el-progress
          :percentage="percentage"
          :style="{'width':'70%','margin':'50px auto','padding-left':'50px'}"
      ></el-progress>
    </div>
    <div class="right-btn-bmiTrue">
      <el-button type="primary" class="BMIprimary"   @click="onDiet" >
        开始膳食测评
      </el-button>
    </div>
    <div class="right-btn-bmiTrue">
      <el-button class="BMIDefault"  @click="onBmiresult">
        BMI分析结果
      </el-button>
    </div>
  </el-card>
  <div :class="{'tan':tan==true,'la':tan==true,'pi':tan==false}">
    <div class="inner">
      <!-- <div class="tu">
        <img src="@/images/icon-area.svg" alt />
      </div>-->
      <!-- <div class="cg">分析完成</div> -->

      <el-drawer
          v-model="drawer"
          title="请选择要操作的内容"

          :direction="direction"
          :before-close="handleClose"
      >
        <div class="drVal">
          <el-tooltip
              class="box-item"
              effect="dark"
              content="点击此按钮进行体成分分析，如果没有反应请多试几次或者联系管理员哦"
              placement="bottom"
          >
            <el-button type="primary" class="btnClick" @click="appraisal">开始体成分测评</el-button>
          </el-tooltip>

        </div>
        <div class="drVal">
          <el-tooltip
              class="box-item"
              effect="dark"
              content="用户测评完成之后，要点击此处，如点击测评无法显示，请先点击测评完毕"
              placement="bottom"
          >
            <el-button type="info" @select="menuActive" class="btnClick"  @click="guanbi">测评完毕</el-button>
          </el-tooltip>

        </div>
        <div class="drVal">
          <el-tooltip
              class="box-item"
              effect="dark"
              content="点击此按钮可以直接查看报告，此报告为体成分分析仪分析报告，请先进行体成分分析检测"
              placement="bottom"
          >
            <el-button type="success" class="btnClick" @click="goto">查看体成分报告</el-button>
          </el-tooltip>
        </div>
        <div class="drVal">
          <el-tooltip
              class="box-item"
              effect="dark"
              content="膳食模型放好之后不要移动，确认放好之后点击此按钮，否则不会显示最新膳食哦"
              placement="bottom"
          >
            <el-button type="warning" @select="menuActive" class="btnClick" @click="onDiet">开始膳食测评</el-button>
          </el-tooltip>
        </div>
      </el-drawer>

      <div class="ksc">
        <div class="zhong">

        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { Edit, CirclePlus, Search, Expand,  } from '@element-plus/icons-vue'
import {defineComponent, onMounted, ref, watch, reactive} from 'vue'
import Header from './common/Header.vue';
import {useRoute, useRouter} from "vue-router"
import http from "../utils/http";
import {ElMessage} from "element-plus";
import AdultLeft from './common/AdultLeft.vue';
const route = useRoute()
const router = useRouter()
const labName = ref()
const groupId = ref()
const id = ref()
const drawer = ref(false)
const direction =  ref('rtl')
const tan =  ref(true)
const reportId =  ref()

const pageList = async () => {
  await router.push({'path': '/AdultList/' + groupId.value})
}
const onBmishow = ref(1)

const percentage =  ref(10)

const handleClose = (done) => {
  done()
}

const goto = async () => {
  const { href } = await router.resolve({
    path:  "/Gravidaanalysis/"+groupId.value+"/"+id.value+"/"+reportId.value
  });
  window.open(href, "_blank");
}

const bmifx = async () => {
  onBmishow.value = 2;
  var timer = setInterval(() => {
    if (percentage.value < 100) {
      percentage.value += 10;
    } else {
      clearInterval(timer);
      setTimeout(() => {
        onBmishow.value = 3;
        //this.$router.push({ path: "cp_two" });
      }, 100);
    }
  }, 100);
}
const onBmiresult = async () => {
  const { href } = await router.resolve({
    path:  "/AdultEvaluationResult/"+groupId.value+"/"+id.value
});
  window.open(href, "_blank");
}
const onDiet = async() => {
  const { href } = await router.resolve({
    path:  "/AdultDiet/"+groupId.value+"/"+id.value+'/'+reportId.value
  });
  window.open(href, "_blank");
}
const onPageAdd = () => {

}

// const menuActive = () => {
//   this.$refs.navdrawer.closeDrawer()
// }

const onHome = async () => {
  await router.push({'path': '/Home'})
}

const appraisal = async ()  => {
  http.get('api/archives/analysis?id='+ id.value+'&type=analysis').then((res)=>{
    if(res.data.code === 0) {
      ElMessage.error(res.data.msg)
    }
  })
}

const guanbi = async ()  => {
  tan.value = false;
  http.get('api/archives/analysis?id='+ id.value+'&type=cancel').then((res)=>{
    if(res.data.code === 0) {
      ElMessage.error(res.data.msg)
    }
  })
}

const fetchData = async () => {
  if(route.params.groupId) {
    groupId.value = route.params.groupId
    id.value = route.params.id
    if(groupId.value == 3) {
      labName.value = '婴幼儿营养测评'
    } else if(groupId.value == 5) {
      labName.value = '孕产妇营养测评'
    } else if(groupId.value == 6) {
      labName.value = '成年人营养测评'
    } else if(groupId.value == 7) {
      labName.value = '慢性病营养测评'
    } else if (groupId.value == 8) {
      labName.value = '团体营养测评'
    } else {
      labName.value = '婴幼儿营养测评'
    }
    http.get('api/adult/setGenerate?id='+ id.value).then((res)=>{
      if(res.data.code === 1) {
        reportId.value = res.data.data.reportId
      } else {
        ElMessage.error(res.data.msg)
        return false
        router.push({'path': '/AdultList/'+ groupId.value})
      }

    })
  } else {
    ElMessage.error('栏目编号不得为空')
    await router.push({'path': '/Home'})
  }
}

onMounted(() => {
  fetchData()
})
</script>

<style scoped>
@import '../assets/css/common.css';
 .BMIprimary {
  width: 268px;
  height: 70px;
  background: #0192f3;
   border: 1px solid #0192f3;
  opacity: 1;
  border-radius: 8px;
  font-size: 24px;
}
.BMIDefault {
  width: 268px;
  height: 70px;
  background: #fff;
  opacity: 1;
  color: #0192f3;
  border-radius: 8px;
  font-size: 24px;
  border:1px solid #0192f3;
}


 ::v-deep .el-button:focus, .el-button:hover {
   background: #0192f3;
   color: #fff;
 }
::v-deep  .el-progress-bar__inner {
  background: #0192f3;
}
</style>
<style>
  .right-box-card {
    margin-left: 2%;
    margin-top: 1%;
    position: static;
    top: calc(260px);
    width: 60%;
    float: left;
    min-height: 650px;
  }
  .right-btn {
    float: left;
    width: 50%;
    text-align: center;
    padding: 238px 0;
    color: #999999;
  }
  .fenxing {
    width: 100%;
    padding-top: 80px;
    box-sizing: border-box;
    font-size: 24px;
  }
  .fxi{
    width: 260px;
    height: 160px;
    /*background: #f5f7fa;*/
    border-radius: 80px;
    margin: 0 auto;
    text-align: center;
    line-height: 340px;
    font-weight: bold;
    font-size: 34px;
    color: #e27350;
    position: relative;
  }
  .fxi img{
    position: absolute;
    top: 40%;
    left: 50%;
    transform: translate(-50%, -50%);
  }
  .wing {
    width: 100%;
    height: 20px;
    line-height: 120px;
    font-size: 24px;
    text-align: center;
    color: #606266;
    margin-top: 20px;
  }

  .right-btn-bmiTrue {
    float: left;
    width: 40%;
    margin-left: 8%;
    text-align: center;
    /* padding: 238px 0; */
    color: #999999;
  }

  .drVal {
    text-align: center;
    padding-top: 70px;
  }
  .btnClick{
    width: 200px;
    height: 100px;
    border-radius: 20px;
    font-size: 16px;
  }
  .tooltip-base-box .row {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  .tooltip-base-box .center {
    justify-content: center;
  }
  .tooltip-base-box .box-item {
    width: 110px;
    margin-top: 10px;
  }

</style>
